/*
 * Germinus
 */
package org.germinus.telcoblocks.servicios.diagram.rcp.part;

import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
import org.germinus.telcoblocks.TelcoblocksPackage;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.AnunciosEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.AnunciosNombreEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.ClickToDialEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.ClickToDialNombreEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.DesvioEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.DesvioNombreEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.EnlaceComentarioEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.EnlaceEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.FacturacionEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.FacturacionNombreEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.IMEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.IMNombreEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.LlamadasEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.LlamadasNombreEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.PersonalizacionEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.PersonalizacionNombreEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.SERVICIOSEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.ServicioGenEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.ServicioGenNombreEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.TelefonoEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.TelefonoNombreEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.WebEditPart;
import org.germinus.telcoblocks.servicios.diagram.rcp.edit.parts.WebNombreEditPart;

/**
 * This registry is used to determine which type of visual object should be
 * created for the corresponding Diagram, Node, ChildNode or Link represented
 * by a domain model object.
 * 
 * @generated
 */
public class TelcoblocksVisualIDRegistry {

	/**
	 * @generated
	 */
	private static final String DEBUG_KEY = "telcoblocks.servicios.diagram.rcp/debug/visualID"; //$NON-NLS-1$

	/**
	 * @generated
	 */
	public static int getVisualID(View view) {
		if (view instanceof Diagram) {
			if (SERVICIOSEditPart.MODEL_ID.equals(view.getType())) {
				return SERVICIOSEditPart.VISUAL_ID;
			} else {
				return -1;
			}
		}
		return org.germinus.telcoblocks.servicios.diagram.rcp.part.TelcoblocksVisualIDRegistry
				.getVisualID(view.getType());
	}

	/**
	 * @generated
	 */
	public static String getModelID(View view) {
		View diagram = view.getDiagram();
		while (view != diagram) {
			EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
			if (annotation != null) {
				return (String) annotation.getDetails().get("modelID"); //$NON-NLS-1$
			}
			view = (View) view.eContainer();
		}
		return diagram != null ? diagram.getType() : null;
	}

	/**
	 * @generated
	 */
	public static int getVisualID(String type) {
		try {
			return Integer.parseInt(type);
		} catch (NumberFormatException e) {
			if (Boolean.TRUE.toString().equalsIgnoreCase(
					Platform.getDebugOption(DEBUG_KEY))) {
				TelcoblocksServiciosDiagramEditorPlugin.getInstance().logError(
						"Unable to parse view type as a visualID number: "
								+ type);
			}
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static String getType(int visualID) {
		return String.valueOf(visualID);
	}

	/**
	 * @generated
	 */
	public static int getDiagramVisualID(EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		if (TelcoblocksPackage.eINSTANCE.getSERVICIOS().isSuperTypeOf(
				domainElement.eClass())
				&& isDiagram((org.germinus.telcoblocks.SERVICIOS) domainElement)) {
			return SERVICIOSEditPart.VISUAL_ID;
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static int getNodeVisualID(View containerView, EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		String containerModelID = org.germinus.telcoblocks.servicios.diagram.rcp.part.TelcoblocksVisualIDRegistry
				.getModelID(containerView);
		if (!SERVICIOSEditPart.MODEL_ID.equals(containerModelID)) {
			return -1;
		}
		int containerVisualID;
		if (SERVICIOSEditPart.MODEL_ID.equals(containerModelID)) {
			containerVisualID = org.germinus.telcoblocks.servicios.diagram.rcp.part.TelcoblocksVisualIDRegistry
					.getVisualID(containerView);
		} else {
			if (containerView instanceof Diagram) {
				containerVisualID = SERVICIOSEditPart.VISUAL_ID;
			} else {
				return -1;
			}
		}
		switch (containerVisualID) {
		case SERVICIOSEditPart.VISUAL_ID:
			if (TelcoblocksPackage.eINSTANCE.getClickToDial().isSuperTypeOf(
					domainElement.eClass())) {
				return ClickToDialEditPart.VISUAL_ID;
			}
			if (TelcoblocksPackage.eINSTANCE.getLlamadas().isSuperTypeOf(
					domainElement.eClass())) {
				return LlamadasEditPart.VISUAL_ID;
			}
			if (TelcoblocksPackage.eINSTANCE.getServicioGen().isSuperTypeOf(
					domainElement.eClass())) {
				return ServicioGenEditPart.VISUAL_ID;
			}
			if (TelcoblocksPackage.eINSTANCE.getPersonalizacion()
					.isSuperTypeOf(domainElement.eClass())) {
				return PersonalizacionEditPart.VISUAL_ID;
			}
			if (TelcoblocksPackage.eINSTANCE.getIM().isSuperTypeOf(
					domainElement.eClass())) {
				return IMEditPart.VISUAL_ID;
			}
			if (TelcoblocksPackage.eINSTANCE.getFacturacion().isSuperTypeOf(
					domainElement.eClass())) {
				return FacturacionEditPart.VISUAL_ID;
			}
			if (TelcoblocksPackage.eINSTANCE.getWeb().isSuperTypeOf(
					domainElement.eClass())) {
				return WebEditPart.VISUAL_ID;
			}
			if (TelcoblocksPackage.eINSTANCE.getDesvio().isSuperTypeOf(
					domainElement.eClass())) {
				return DesvioEditPart.VISUAL_ID;
			}
			if (TelcoblocksPackage.eINSTANCE.getAnuncios().isSuperTypeOf(
					domainElement.eClass())) {
				return AnunciosEditPart.VISUAL_ID;
			}
			if (TelcoblocksPackage.eINSTANCE.getTelefono().isSuperTypeOf(
					domainElement.eClass())) {
				return TelefonoEditPart.VISUAL_ID;
			}
			break;
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static boolean canCreateNode(View containerView, int nodeVisualID) {
		String containerModelID = org.germinus.telcoblocks.servicios.diagram.rcp.part.TelcoblocksVisualIDRegistry
				.getModelID(containerView);
		if (!SERVICIOSEditPart.MODEL_ID.equals(containerModelID)) {
			return false;
		}
		int containerVisualID;
		if (SERVICIOSEditPart.MODEL_ID.equals(containerModelID)) {
			containerVisualID = org.germinus.telcoblocks.servicios.diagram.rcp.part.TelcoblocksVisualIDRegistry
					.getVisualID(containerView);
		} else {
			if (containerView instanceof Diagram) {
				containerVisualID = SERVICIOSEditPart.VISUAL_ID;
			} else {
				return false;
			}
		}
		switch (containerVisualID) {
		case ClickToDialEditPart.VISUAL_ID:
			if (ClickToDialNombreEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case LlamadasEditPart.VISUAL_ID:
			if (LlamadasNombreEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case ServicioGenEditPart.VISUAL_ID:
			if (ServicioGenNombreEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PersonalizacionEditPart.VISUAL_ID:
			if (PersonalizacionNombreEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case IMEditPart.VISUAL_ID:
			if (IMNombreEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case FacturacionEditPart.VISUAL_ID:
			if (FacturacionNombreEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case WebEditPart.VISUAL_ID:
			if (WebNombreEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case DesvioEditPart.VISUAL_ID:
			if (DesvioNombreEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case AnunciosEditPart.VISUAL_ID:
			if (AnunciosNombreEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case TelefonoEditPart.VISUAL_ID:
			if (TelefonoNombreEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case SERVICIOSEditPart.VISUAL_ID:
			if (ClickToDialEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (LlamadasEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ServicioGenEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PersonalizacionEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (IMEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (FacturacionEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (WebEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (DesvioEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (AnunciosEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (TelefonoEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case EnlaceEditPart.VISUAL_ID:
			if (EnlaceComentarioEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		}
		return false;
	}

	/**
	 * @generated
	 */
	public static int getLinkWithClassVisualID(EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		if (TelcoblocksPackage.eINSTANCE.getEnlace().isSuperTypeOf(
				domainElement.eClass())) {
			return EnlaceEditPart.VISUAL_ID;
		}
		return -1;
	}

	/**
	 * User can change implementation of this method to handle some specific
	 * situations not covered by default logic.
	 * 
	 * @generated
	 */
	private static boolean isDiagram(org.germinus.telcoblocks.SERVICIOS element) {
		return true;
	}

}
